<%@page import="evol.Rezultat"%>
<%@page import="evol.Predmet"%>

<%@ page import="evol.Istrazivanje"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<head>
<script type="text/javascript">
	function dodaj() {
		div1 = document.getElementById('container').lastElementChild

		b1 = div1.cloneNode(true)

		a = b1.firstElementChild
		a2 = b1.lastElementChild

		a = a.cloneNode(true)
		a2 = a2.cloneNode(true)

		b1.removeChild(b1.firstElementChild);
		b1.removeChild(b1.lastElementChild);

		b = a.cloneNode(true)
		if (b.type == "select-one") {
			id2 = b.name.split('-')
			id = parseInt(id2[1]) + 1
			b.name = id2[0] + "-" + id
			b.id = id2[0] + "-" + id

			b[0].innerHTML = "- izaberite predmet - "
		}

		b1.appendChild(b);

		b = a2.cloneNode(true)
		if (b.type == "select-one") {
			id2 = b.name.split('-')
			id = parseInt(id2[1]) + 1
			b.name = id2[0] + "-" + id
			b.id = id2[0] + "-" + id

			b[0].innerHTML = "- izaberite predmet - "
		}

		b1.appendChild(b);

		document.getElementById('container').appendChild(b1)

	}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="main" />
<title>Istrazivanje</title>
</head>
<body>
	<div class="body">
		<h1 style="margin-left: 1%">
			Naziv istrazivanja :
			${is.naziv}
			- metodologija :${is.metodologija}
		</h1>
		<h3 style="margin-left: 1%">
			Opis:
			${is.opis}
		</h3>

		<form action="createSelect" >
		<input type="hidden"  name="idIstr" value="${params.idIstrazivanja }"/>
			<div id="container" style="margin: 5px">
			
				<g:each in="${lista}" status="i" var="istrInstance">
				
					<div id="par">
					
						<g:select style="margin:2px" name="predmet1-${i}"
							from="${Predmet.list()}" value="${fieldValue(bean: istrInstance.getAt('predmet1'), field: 'naziv')}"
							noSelection="${[[fieldValue(bean: istrInstance.getAt('predmet1'), field: 'naziv')]:fieldValue(bean: istrInstance.getAt('predmet1'), field: 'naziv')] }"
							 />
						
						<g:set var="moj" value="${ fieldValue(bean:istrInstance.getAt('predmet2'), field: 'naziv')}" scope="page" />
						<g:select style="margin:2px" name="predmet2-${i}"
							from="${Predmet.list()}" value="${moj }"
							noSelection="${[[fieldValue(bean: istrInstance.getAt('predmet2'), field: 'naziv')]:fieldValue(bean: istrInstance.getAt('predmet2'), field: 'naziv')] }"
							 />
					</div>
		
				</g:each>
				
				<g:if test="${lista.empty }">
				
				<div id="par">
					
						<g:select style="margin:2px" name="predmet1-0"
							from="${Predmet.list()}" value="predmet1"
											noSelection="${['':'--izaberite predmet--'] }"			 />
						
						
						<g:select style="margin:2px" name="predmet2-0"
							from="${Predmet.list()}" value="predmet2"
							noSelection="${['':'--izaberite predmet--'] }"
							 />
					</div>
				</g:if>
			</div>
			<a  style="margin-top: 10px; margin-left: 3%;" onclick="dodaj();">
				+ Dodaj jos vezu</a>
	</div>


	<input type="submit" style="margin-top: 5%; margin-left: 30%;"
	value="Sacuvaj istrazivanje"/><%--
	
		onclick='window.location.assign("/Evolucija1/istrazivanje/createSelect")' 
	--%></form>
</body>
</html>